<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<base href="<%=basePath%>">
<title>代理商</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/bootstrap.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/main.css">
<link rel="stylesheet"
	href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/js/main.js"></script>
<script src="${pageContext.request.contextPath}/js/jqueryui.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.4.5/angular.min.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script src="${pageContext.request.contextPath}/js/MD5.js"></script>
<style>
.main_div {
	min-width: 1000px
}

.pageChange {
	padding-left: 20px;
	color: #337ab7;
}

.box_content {
	height: 100px;
	padding-left: 30px
}

.pageChange>span {
	cursor: pointer
}

.pageChange>span:hover {
	color: blue
}
</style>
<script>
	$(function() {
		$("#startTime").datepicker();
		$("#endTime").datepicker();
		$("#startTime").datepicker("option", "dateFormat", "yy-mm-dd");
		$("#endTime").datepicker("option", "dateFormat", "yy-mm-dd");
	})
</script>
</head>
<body>
	<%@ include file="header.jsp"%>
	<%@ include file="left.jsp"%>
	<div id="index"
		style="position: absolute;left: 180px;top: 80px;bottom: 0;right: 0;">
		<section id="main">
			<div class="scrollbar1-1" id="style1-1">
				<div class="main_div">
					<div class="main_title">
						<span>订单明细</span>
					</div>
					<form class="form-inline" id="detailForm" action="" method="post"
						style="margin-top: 30px;margin-left: 20px">
						<input style="display:none" value="7" id="pageCount"
							name="pageCount" />
						<div class="form-group">
							<label for="ProductName"> 开始时间:</label> <input type="text"
								class="form-control" name="" id="startTime" placeholder="">
						</div>
						<div class="form-group">
							<label for="userName"> -结束时间:</label> <input type="text"
								class="form-control" name="" id="endTime" placeholder="">
						</div>
						<div class="form-group">
							<label for="userName"> 订单编号</label> <input type="text"
								class="form-control" name="" id="orderFormId" placeholder="">
						</div>
						<div class="form-group">
							<label>订单状态:</label> <select class="form-control" id="status"
								name="orderType">
								<option value="-1">请选择</option>
								<option value="1">待发货</option>
								<option value="2">待收货</option>
								<option value="3">已完成</option>
								<option value="4">已评价</option>
								<option value="5">已退货（未处理）</option>
								<option value="6">已退货（已处理）</option>
							</select>
						</div>
						<div class="form-group">
							<label>支付方式:</label> <select class="form-control" id="payway">
								<option value="-1">请选择</option>
								<option value="2">在线支付</option>
								<option value="1">货到付款</option>
							</select>
						</div>
						<button onclick="selectinfo()" type="button"
							class="btn btn-primary">立即查询</button>
					</form>
				</div>
				<div class="force-overflow1-1">
					<table id="showtable"
						class="table table-condensed table-bordered table-hover"
						show-filter="true" style="text-align: center">
						<tr style="background-color: #59c7d2">
							<th style="text-align: center">序号</th>
							<th style="text-align: center">订单编号</th>
							<th style="text-align: center">订单状态</th>
							<th style="text-align: center">支付方式</th>
							<th style="text-align: center">购买人</th>
							<th style="text-align: center">联系电话</th>
							<th style="text-align: center">订单金额</th>
							<th style="text-align: center">订单时间</th>
							<th style="text-align: center">订单详情</th>
						</tr>
					</table>
					<div class="pageChange">
						<span onclick="prePage()">&nbsp;&nbsp;上一页&nbsp;&nbsp;</span> <span
							onclick="nextPage()">&nbsp;&nbsp;下一页&nbsp;&nbsp;</span> <em>
							&nbsp; 第&nbsp;<span id="pageNum">1</span>&nbsp;页&nbsp;&nbsp;
						</em> <em>/&nbsp;&nbsp;共&nbsp;<span id="totalpage"></span>&nbsp;页
						</em> <em>&nbsp;&nbsp;&nbsp;跳到第<input id="searchInput"
							style="width:46px" maxlength="4" type="text">页
						</em>
						<button type="submit" class="btn btn-primary"
							onclick="searchPage()">搜索</button>
					</div>
				</div>
			</div>
		</section>
		<div class="bgBox" id="motai" style="visibility:hidden">
			<div id="box">
				<div class="box_header textYellow">
					<span>详细资料</span>
				</div>
				<div class="scrollbar1-2" id="style1-1">
					<div class="box_content" id="box_content"></div>
					<div class="force-overflow1-2"></div>
				</div>
				<div class="box_footer">
					<ul>
						<li id="sureDetail" onclick="motaiHidden()">确认</li>
						<li id="sureDetail" onclick="motaiHidden()">打印</li>
					</ul>
				</div>
			</div>
		</div>

	</div>
	<script>
		$(function() {
			selectinfo()
		})
	
		
	
		function selectinfo() {
			var URL = document.location.toString();
			var sperIDs = URL.split("=")[1]
			var orderFormId = $("#orderFormId").val();
			var pageNum = $("#pageNum").html();
			var pageCount = $("#pageCount").val();
			var idstatus = $("#status").find("option:selected").val();
			var payway = $("#payway").find("option:selected").val();
			var startTime = $("#startTime").val();
			var endTime = $("#endTime").val();
			if (startTime == "") {
				startTime = null
			} else {
				startTime = startTime + " 00:00:00"
			}
			if (endTime == "") {
				endTime = null
			} else {
				endTime = endTime + " 23:59:59"
			}
			if (idstatus == "-1") {
				idstatus = null
			}
			if (payway == "-1") {
				payway = null
			}
			if (orderFormId == "") {
				orderFormId = null;
			}
			$.post(urls + "orderFormAction/getOrderFormBySuperInfo",
				{
					superId : sperIDs,
					startTime : startTime,
					endTime : endTime,
					paymentType : payway,
					status : idstatus,
					orderFromId : orderFormId,
					pageNum : pageNum,
					pageCount : pageCount,
				},
				function(data) {
					//console.log(data)
					if (data) {
						var totalpage = data.totalpage;
						var orderlist = data.orderlist;
						var table = $("#showtable");
						$("tr").remove(".addtr");
						for (var i = 0; i < orderlist.length; i++) {
							var status = orderlist[i].status;
							if (status == 1) {
								status = "待发货"
							} else if (status == 2) {
								status = "待收货"
							} else if (status == 3) {
								status = "已完成"
							} else if (status == 4) {
								status = "待评价"
							} else if (status == 5) {
								status = "退货（未处理）"
							} else if (status == 6) {
								status = "退货（已处理）"
							} else if (status == 7) {
								status = "投诉"
							}else if (status == 8) {
								status = "已完毕"
							}
							var paymentType = orderlist[i].paymentType
							if (paymentType == 1) {
								paymentType = "货到付款"
							} else if (paymentType == 2) {
								paymentType = "在线支付"
							}
							var append = "<tr class='addtr'><td>" + (i + 1) + "</td>" +
								"<td >" + orderlist[i].orderFormId + "</td>" +
								"<td>" + status + "</td>" +
								"<td>" + paymentType + "</td>" +
								"<td>" + orderlist[i].userName + "</td>" +
								"<td>" + orderlist[i].phone + "</td>" +
								"<td>￥" + orderlist[i].totalMoney + "</td>" +
								"<td>" + orderlist[i].orderFormTime + "</td>" +
								"<td><input onclick='detailinfo(\"" + orderlist[i].orderFormId + "\")' type='button' class='btn btn-primary' value='订单详情' /></td></tr>";
							table.append(append);
						}
						$("#totalpage").html(totalpage);
					}
				}
				, "json"
			)
		}
	
		function detailinfo(e) {
			$.post(urls + "orderFormAction/getOrderFormDetailsByOrderFormID",
				{
					orderFormId : e
				},
				function(data) {
					console.log(data)
					$("#motai").css("visibility", "visible")
					var box_content = $("#box_content");
					$("#box_content").empty();
					for (var z in data) {
						var append2 = "<div><div style='width:100%;height:20px;'></div>" +
							"<span>产品名称:</span>&nbsp;&nbsp;&nbsp;<span>" + data[z].productName + "</span>" +
							"</div>" +
							"<div>" +
							"<span>产品单价:</span>&nbsp;&nbsp;&nbsp;<span>" + data[z].unitPrice + "</span>" +
							"</div>" +
							"<div>" +
							"<span>产品数量:</span>&nbsp;&nbsp;&nbsp;<span>" + data[z].quantity + "</span>" +
							"</div>" +
							"<div>" +
							"<span>产品总价:</span>&nbsp;&nbsp;&nbsp;<span>" + data[z].totalPrices + "</span>" +
							"</div>"
						box_content.append(append2);
					}
	
				}, "json"
			)
	
		}
		function motaiHidden() {
			$("#motai").css("visibility", "hidden")
		}
	</script>
</body>
</html>
